/* This this the only include needed in your code .*/
#include "femtoos_code.h"
#include "adc.h"

#ifdef OPT_ADC_SUPPORT

//---------------------------
// Functions
//---------------------------
void InitAdc()
{
    // ADC initialization
    // ADC Clock frequency: 62.500 kHz
    // ADC Voltage Reference: AREF pin
    // ADC Auto Trigger Source: None
    ADMUX=ADC_VREF_TYPE & 0xff;
    ADCSRA=0x86;

}

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
    ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
    // Delay needed for the stabilization of the ADC input voltage
    taskDelayFromNow(1);
    // Start the AD conversion
    ADCSRA|=0x40;
    // Wait for the AD conversion to complete
    while ((ADCSRA & 0x10)==0)
    {	
    	taskDelayFromNow(1);
    }
    ADCSRA|=0x10;
    return ADCW;
}

#else /*OPT_ADC_SUPPORT*/

void InitAdc(){}
unsigned int read_adc(unsigned char adc_input){return 0;}

#endif /*OPT_ADC_SUPPORT*/
